<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 引包 -->
    <script src="../js/vue.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        ul {
            width: 180px;
            list-style: none;
            background: rgb(167, 145, 149);
        }

        li {
            width: 100%;
            height: 50px;
            text-align: center;
            line-height: 50px;
            border-bottom: 1px solid rgb(218, 108, 108);
            color: #ffff;
        }
        .active{background: red;}
    </style>
</head>

<body>
    <!-- 容器|模板 -->
    <div id="app">
        <ul>
            <li v-for="(item,index) in list" :key="item.id" @mouseenter="handle(index)" :class="{active:currentIndex===index}">{{item.title}}---{{index}}</li>
        </ul>
    </div>
</body>

</html>
<script>
    //关联VM
    const VM = new Vue({
        el: '#app',
        data: {
            list: [
                { id: 100, title: "开心超人" },
                { id: 990, title: "伤心超人" },
                { id: 550, title: "黑心超人" },
                { id: 220, title: "小心超人" },
                { id: 880, title: "夹心超人" },
                { id: 440, title: "甜心超人" },
            ],
            //这个响应式属性存储用户鼠标移入那个元素的索引值
            currentIndex:0

        },
        methods:{
            handle(index){
                this.currentIndex = index
            }
        }
    })
</script>